﻿@model IEnumerable<QuanLyGiaoVuUI.Models.GiangVien.GiangVienViewModel>

@{
    Layout = null;
}

<style>
    .table-holder {
        height: 450px;
    }
</style>

    <input type="hidden" value="" id="selectedGiangVienId" />
    <input type="hidden" value="" id="thongtinGiangVien" />
    <div class="table-holder">
    <table class="data display datatable" id="GiangVienTable">
        <tr>
            <th class="sorting">
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.MaGiangVien)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.HoTenGV)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.GioiTinh)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.NgaySinh)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.NgayVaoCongTac)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.MaHocVi)
            </th>
            <th class="sorting">
                @Html.DisplayNameFor(model => model.MaHocHam)
            </th>
        </tr>
    
        @{int count = 0;}
    @foreach (var item in Model) {
        <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
            <td class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                @Html.RadioButton("ID", item.ID, new { @class = "selectGiangVienId" })
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MaGiangVien)
            </td>
            <td class="hoTenGV">
                @Html.DisplayFor(modelItem => item.HoTenGV)
            </td>
            <td>
                @(item.GioiTinh.Equals("1") ? "Nam" : "Nữ")
            </td>
            <td>
                <span>@(item.NgaySinh.HasValue ? ((DateTime)item.NgaySinh).ToShortDateString() : String.Empty)</span>
            </td>
            <td>
                <span>@item.NgayVaoCongTac.ToShortDateString()</span>
            </td>
            <td class="hocViVT">
                @item.HocVi.VietTat
            </td>
            <td class="hocHamVT">
                @(item.HocHam != null ? item.HocHam.VietTat : "")
            </td>
        </tr>
    }
    </table>
        </div>
    <script>
        $(document).ready(function () {
            $("#GiangVienTable tr").each(function () {
                $(this).click(function () {
                    var selectedRadio = $(this).find("input[type=radio]").first();
                    var selectedGiangVienId = selectedRadio.val();
                    $(this).find("input[type=radio]").attr('checked', true);
                    $("#selectedGiangVienId").val(selectedGiangVienId);
                    var hoTenGV = selectedRadio.parent().parent().find(".hoTenGV").first().html().trim();
                    var hocHam = selectedRadio.parent().parent().find(".hocHamVT").first().html().trim();
                    if (hocHam.length > 0)
                        hocHam = hocHam.trim() + ". ";
                    var hocVi = selectedRadio.parent().parent().find(".hocViVT").first().html().trim();
                    $("#thongtinGiangVien").val((hocHam + hocVi + ". " + hoTenGV).trim());
                });
            });

            $(".selectGiangVienId").each(function () {
                $(this).click(function () {
                    $("#selectedGiangVienId").val($(this).val());
                    var hoTenGV = $(this).parent().parent().find(".hoTenGV").first().html().trim();
                    var hocHam = $(this).parent().parent().find(".hocHamVT").first().html().trim();
                    if (hocHam.length > 0)
                        hocHam = hocHam.trim() + ". ";
                    var hocVi = $(this).parent().parent().find(".hocViVT").first().html().trim();
                    $("#thongtinGiangVien").val((hocHam + hocVi + ". " + hoTenGV).trim());
                });
            });
        });
    </script>
